package com.xrj.gateway.exception;

import com.mall.common.exception.AuthFailException;
import com.mall.common.exception.BizException;
import com.mall.common.exception.UserBizException;
import com.mall.common.response.Response;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.net.SocketTimeoutException;


/**
 * @author: xrj
 * @date: 2022/4/28 23:06
 * @description:
 */

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 异常处理
     */
    @ExceptionHandler(Throwable.class)
    public Object handException(Throwable ex) {
        String msg = ex.getMessage();
        log.error("系统异常捕获:{}", msg, ex);
        if (ex instanceof IllegalArgumentException) {
            return Response.requestFailed("参数异常!");
        }
        if (ex instanceof HttpRequestMethodNotSupportedException) {
            return Response.requestFailed("请求接口不支持!");
        }
        if (ex instanceof SocketTimeoutException) {
            return Response.requestFailed("连接超时!");
        }
        return Response.requestFailed("未知异常!");
    }

}
